<template>
  <div>
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="12" :sm="12">
            <a-form-item :label="$t('m.system.dict.entity.dictName')">
              <a-input :placeholder="$t('m.system.dict.other.name_code_placeholder')"  v-model="queryParam.dictName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{ $t('m.common.button.query') }}</a-button>
              <a-button type="default" @click="searchReset" icon="reload" style="margin-left: 8px">{{ $t('m.common.button.reset') }}</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <a-table
      ref="table"
      :rowKey="rowKey"
      bordered
      size="middle"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type: (radio ? 'radio' : 'checkbox')}"
      @change="handleTableChange"
      :customRow="clickThenCheck">
      <template slot="serialNum" slot-scope="text,record,index">
        {{(ipagination.current-1) * ipagination.pageSize + parseInt(index) + 1}}
      </template>
    </a-table>
  </div>
</template>

<script>

  import { YcListMixin } from '@/mixins/YcListMixin'
  import YchConstant from "@/api/YchConstant";
  import LocaleUtil from '../../../../utils/LocaleUtil';

  export default {
    name: 'DictList',
    mixins: [YcListMixin],
    props: {
      radio: {
        type: Boolean,
        default: false
      },
      groupId: {
        type: String,
        required: true
      }
    },
    data () {
      return {
        columns: [
          {
            title:this.$t('m.common.label.number'),
            dataIndex: '',
            key: 'rowIndex',
            width: 50,
            align: 'center',
            scopedSlots: { customRender: 'serialNum' },
          },
          {
            title: this.$t('m.system.dict.entity.dictName'),
            align: 'center',
            dataIndex: 'dictName',
          },
          {
            title: this.$t('m.system.dict.entity.dictCode'),
            align: 'center',
            dataIndex: 'dictCode',
          },
          {
            title: this.$t('m.system.dict.entity.category'),
            align: "center",
            width: 100,
            dataIndex: 'category',
            customRender:function (text) {
              if(text=='0'){
                return LocaleUtil.getLocale('m.system.dict.other.option_category0');
              }else if(text=='1'){
                return LocaleUtil.getLocale('m.system.dict.other.option_category1');
              }else{
                return LocaleUtil.getLocale('m.system.dict.other.option_category2');
              }
            }
          },
        ],
        url: {
          list: YchConstant.PREFIX_SYSTEM + '/dict/listCommonAndAppOr',
        },
        queryParam: {
          groupId: this.groupId,
        },
      }
    },
    methods: {
      searchReset () {
        this.queryParam = {
          groupId: this.groupId,
        }
        this.loadData(1)
      },
    },
  }
</script>
